package com.styletransfer.controller;

import com.styletransfer.model.ApiResponse;
import com.styletransfer.model.User;
import com.styletransfer.service.UserFollowService;
import com.styletransfer.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/follow")
public class UserFollowController {

    @Autowired
    private UserFollowService userFollowService;

    @Autowired
    private UserService userService;

    /**
     * 关注用户
     * @param followingId 要关注的用户ID
     * @return 操作结果
     */
    @PostMapping("/{followingId}")
    public ApiResponse<Void> followUser(@PathVariable Long followingId) {
        Long userId = userService.getCurrentUserId();
        return userFollowService.followUser(userId, followingId);
    }

    /**
     * 取消关注用户
     * @param followingId 要取消关注的用户ID
     * @return 操作结果
     */
    @PostMapping("/{followingId}/cancel")
    public ApiResponse<Void> unfollowUser(@PathVariable Long followingId) {
        Long userId = userService.getCurrentUserId();
        return userFollowService.unfollowUser(userId, followingId);
    }

    /**
     * 检查是否已关注用户
     * @param followingId 要检查的用户ID
     * @return 是否已关注
     */
    @GetMapping("/{followingId}/check")
    public ApiResponse<Boolean> checkFollowing(@PathVariable Long followingId) {
        Long userId = userService.getCurrentUserId();
        return userFollowService.checkFollowing(userId, followingId);
    }

    /**
     * 获取用户的关注列表
     * @return 关注的用户ID列表
     */
    @GetMapping("/following")
    public ApiResponse<List<User>> getFollowing() {
        Long userId = userService.getCurrentUserId();
        return userFollowService.getFollowing(userId);
    }

    /**
     * 获取用户的粉丝列表
     * @return 粉丝用户ID列表
     */
    @GetMapping("/followers")
    public ApiResponse<List<User>> getFollowers() {
        Long userId = userService.getCurrentUserId();
        return userFollowService.getFollowers(userId);
    }
}
